
import {createRouter, createWebHashHistory} from "vue-router";
import {Session} from "/@utils/StorageTools";

import {useUserConfig} from "/@bean/GlobalConfig";


// 静态路由
const router = createRouter({
    history : createWebHashHistory(),
    routes: [
        {
            name:'MainIndex',
            path:'/',
            // @ts-ignore
            component:()=>import('/src/pages/home/MainIndex.vue'),
            meta:{
                title:'首页',
                keepAlive:true
            },
            children:[
                {
                    name:'userList',
                    path:'/admin/UserList',
                    // @ts-ignore
                    component:()=>import('/@page/admin/UserList.vue'),
                    meta:{
                        title:'用户列表',
                        keepAlive:true
                    }
                },
                {
                    name:'UserInfoPage',
                    path:'/userInfo',
                    // @ts-ignore
                    component:()=>import('/@page/user/UserInfoPage.vue')
                },
                {
                    name:'ChangePasswordPage',
                    path:'/changePassword',
                    // @ts-ignore
                    component:()=>import('/@page/user/ChangePasswordPage.vue')
                },
                {
                    name:'AgeCount-Page',
                    path:'/AgeCount-Page',
                    // @ts-ignore
                    component:()=>import('/@page/crud/AgeCount-Page.vue')
                },
                {
                    name:'CommitCount-Page',
                    path:'/CommitCount-Page',
                    // @ts-ignore
                    component:()=>import('/@page/crud/CommitCount-Page.vue')
                },
                {
                    name:'CreationTimeCount-Page',
                    path:'/CreationTimeCount-Page',
                    // @ts-ignore
                    component:()=>import('/@page/crud/CreationTimeCount-Page.vue')
                },
                {
                    name:'GenderCount-Page',
                    path:'/GenderCount-Page',
                    // @ts-ignore
                    component:()=>import('/@page/crud/GenderCount-Page.vue')
                },
                {
                    name:'GoodsIdCount-Page',
                    path:'/GoodsIdCount-Page',
                    // @ts-ignore
                    component:()=>import('/@page/crud/GoodsIdCount-Page.vue')
                },
                {
                    name:'ImgCount-Page',
                    path:'/ImgCount-Page',
                    // @ts-ignore
                    component:()=>import('/@page/crud/ImgCount-Page.vue')
                },
                {
                    name:'JdGood-Page',
                    path:'/JdGood-Page',
                    // @ts-ignore
                    component:()=>import('/@page/crud/JdGood-Page.vue')
                },
                {
                    name:'KeywordCount-Page',
                    path:'/KeywordCount-Page',
                    // @ts-ignore
                    component:()=>import('/@page/crud/KeywordCount-Page.vue')
                },
                {
                    name:'PriceCount-Page',
                    path:'/PriceCount-Page',
                    // @ts-ignore
                    component:()=>import('/@page/crud/PriceCount-Page.vue')
                },
                {
                    name:'ShopCount-Page',
                    path:'/ShopCount-Page',
                    // @ts-ignore
                    component:()=>import('/@page/crud/ShopCount-Page.vue')
                },
                {
                    name:'ShopIdCount-Page',
                    path:'/ShopIdCount-Page',
                    // @ts-ignore
                    component:()=>import('/@page/crud/ShopIdCount-Page.vue')
                },
                {
                    name:'TitleCount-Page',
                    path:'/TitleCount-Page',
                    // @ts-ignore
                    component:()=>import('/@page/crud/TitleCount-Page.vue')
                },
                {
                    name:'UserGood-Page',
                    path:'/UserGood-Page',
                    // @ts-ignore
                    component:()=>import('/@page/crud/UserGood-Page.vue')
                },
                {
                    name:'BigScreenPage',
                    path:'/bigScreen',
                    // @ts-ignore
                    component:()=>import('/@page/bigScreen/BigScreen.vue')
                },
                {
                    name:'BigScreenPage1',
                    path:'/bigScreen1',
                    // @ts-ignore
                    component:()=>import('/@page/bigScreen/BigScreen1.vue')
                },
                {
                    name:'BigScreenPage2',
                    path:'/bigScreen2',
                    // @ts-ignore
                    component:()=>import('/@page/bigScreen/BigScreen2.vue')
                },
                {
                    name:'BigScreenPage3',
                    path:'/bigScreen3',
                    // @ts-ignore
                    component:()=>import('/@page/bigScreen/BigScreen3.vue')
                },
                {
                    name:'BigScreenPage4',
                    path:'/bigScreen4',
                    // @ts-ignore
                    component:()=>import('/@page/bigScreen/BigScreen4.vue')
                },
                {
                    name:'BigScreenPage5',
                    path:'/bigScreen5',
                    // @ts-ignore
                    component:()=>import('/@page/bigScreen/BigScreen5.vue')
                }
                ,
                {
                    name:'BigScreenPage6',
                    path:'/bigScreen6',
                    // @ts-ignore
                    component:()=>import('/@page/bigScreen/BigScreen6.vue')
                },
                {
                    name:'BigScreenPage7',
                    path:'/bigScreen7',
                    // @ts-ignore
                    component:()=>import('/@page/bigScreen/BigScreen7.vue')
                },
            ]
        },
        {
            name:'LoginPage',
            path:'/login',
            // @ts-ignore
            component:()=>import('/@page/login/LoginIndex.vue')
        },

    ]
})


// 登录拦截
router.beforeEach((to, from, next):void => {
    const useUser = useUserConfig();
    const { userInfo } = storeToRefs(useUser);
    // 正则匹配 以 /demo 开头的路由 或者 /login /register 及/ 本身 无需登录即可访问
    if (to.path.match(/^\/demo/) || to.path === '/login' || to.path === '/register') {
        next()
    }
    else {
        let token = userInfo.value.token;
        if (token === null) {
            next('/login')
        } else {
            next()
        }
    }
})

export default router
    